package Sampling;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;

import Definitions.GraphClass;
import Global.ConstantVariable;
import Global.GlobalClass;

public class SamplingTests 
{
	
	public static void SamplingTest(GraphClass g, GlobalClass global) throws Exception
	{
		SamplingFactory samplingFactory = new SamplingFactory();
		
		SamplingAbstractClass sampling=samplingFactory.createSampling(createDummyParametresForSampling(ConstantVariable.Sampling_Constants.SNOWBALL_SAMPLING_METHOD), g, global);
		
		System.out.println(sampling.getName());
		
		 try{
			    // Create file
			 	System.out.println("CITESEER_Folds_TestRatio"+sampling.testRatio+"_UnusedRatio_"+sampling.valRatio);
			    FileWriter fstream = new FileWriter("CITESEER_Folds_TestRatio"+sampling.testRatio+"_UnusedRatio_"+sampling.valRatio+"_RS.txt");
			    BufferedWriter out = new BufferedWriter(fstream);
			 
			    for(int i=0;  i<10 ;i++)
			    {
					sampling.generateSampling(g,i);
					sampling.getSamplingResult();	
	
			    	System.out.println("Fold :  " + i);
			    	out.write("Fold: "+i);
			    	out.newLine();
				    out.write("Test Nodes:");
			    	out.newLine();
				    System.out.println("Test Nodes Order");
				    
				    for(int m=0;m<g.getDataSet().size() ;m++)
				    {
				    	if(sampling.isTheNodeInTestSetForTheFold(g.getDataSet().get(m)))
				    	{
				    		out.write(g.getDataSet().get(m).getOrder()+" ");
				    		System.out.print("*"+g.getDataSet().get(m).getOrder()+" ");
				    	}
				    }
				    System.out.println();
				    out.newLine();
				    out.write("Train Nodes:");
				    System.out.println("Train Nodes Order");
				    out.newLine();
				    for(int m=0;m<g.getDataSet().size() ;m++)
				    {
				    	if(sampling.isTheNodeInTrainingSetForTheFold(g.getDataSet().get(m)))
				    	{
				    		out.write(g.getDataSet().get(m).getOrder()+" ");
				    		System.out.print("*"+g.getDataSet().get(m).getOrder()+" ");
				    	}
				    }
				    System.out.println();
				    out.newLine();
		
				    //Close the output stream
				    sampling.initializeTestTrainValidationAssignmentsForTheFold();
			    }
			 out.close();
		 }
		 catch (Exception e)
		 {//Catch exception if any

			 System.err.println("Error: " + e.getMessage());
		 }

	}


	public static ArrayList<Object> createDummyParametresForSampling (String name)
	{
		ArrayList<Object> paramList = new ArrayList<Object> ();
		paramList.add(name);
		if(name == ConstantVariable.Sampling_Constants.SNOWBALL_SAMPLING_METHOD)
		{
			
			
			paramList.add(ConstantVariable.Sampling_Constants.EXECUTION_SAMPLING_TEST_RATIO);
			paramList.add(ConstantVariable.Sampling_Constants.EXECUTION_SAMPLING_VALIDATION_RATIO);
			
			//edgetest
			//paramList.add( (double)0.95 );
			paramList.add(0);
			paramList.add(1);
			paramList.add((double)0.9);
			
			
		}
		/*
		if(name == ConstantVariable.Sampling_Constants.SNOWBALL_SAMPLING_METHOD && i==2)
		{
			System.out.println("set param");
			paramList.add( (double)0.25 );
			paramList.add( (double)0.50 );
			/*edge
			paramList.add( 0 );
			/*degree
			paramList.add( 1 );
			paramList.add( (double)0.95 );
			
		}
		if(name == ConstantVariable.Sampling_Constants.SNOWBALL_SAMPLING_METHOD && i==3)
		{
			System.out.println("set param");
			paramList.add( (double)0.25 );
			paramList.add( (double)0.25 );
			/*edge
			paramList.add( 0 );
			/*degree
			paramList.add( 1 );
			paramList.add( (double)0.95 );
			
		}
		*/
		if(name== ConstantVariable.Sampling_Constants.RANDOM_SAMPLING_METHOD)
		{
			paramList.add(ConstantVariable.Sampling_Constants.EXECUTION_SAMPLING_TEST_RATIO);
			paramList.add(ConstantVariable.Sampling_Constants.EXECUTION_SAMPLING_VALIDATION_RATIO);
			/*size*/
			paramList.add( 270 ) ;
		
		}
		return paramList;
	}
}
